//
// Created by xiaoma on 2/2/21.
//

#ifndef HORSE_VM_MAP_H
#define HORSE_VM_MAP_H

#include "source/object/Universe.h"
#include "../object/HiObject.h"

template<typename K, typename V>
class MapEntry {
public:
    K k;
    V v;

    MapEntry(K k, V v) : k(k), v(v) {}

    MapEntry() : k(0), v(0) {}

    MapEntry(const MapEntry<K, V> &mapEntry);
};

template<typename K, typename V>
class Map {
public:
    Map(int n = 8);

    V getValue(K k) const;

    void put(K k, V v);

    bool hasKey(K k);

    V remove(K k);

    int size() const { return _size; }

    MapEntry<K, V> *entries() { return _entries; }

private:
    MapEntry<K, V> *_entries;
    int _size;
    int _len;

    void expand();

    int getIndex(K k) const;
};

#endif //HORSE_VM_MAP_H
